﻿using System;
using System.Threading;
using System.Windows;

namespace jSLApp.Client.Controls
{
    public partial class CustomBrowser
    {
        public CustomBrowser()
        {
            InitializeComponent();
            Loaded += (sender, args) =>
                          {
                              if(IsEnabled)
                              {
                                  new System.Threading.Tasks.Task(() =>
                                                                      {
                                                                          Thread.Sleep(200);
                                                                          Dispatcher.BeginInvoke(() => {
                                                                                                          browser.Visibility = Visibility.Visible;
                                                                                                       });
                                                                      }).Start();
                                  
                              }
                          };
            IsEnabledChanged+=OnIsEnabledChanged;
        }

        private void OnIsEnabledChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
            browser.Visibility = (bool) args.NewValue?Visibility.Visible : Visibility.Collapsed;
        }

        public string HtmlSource
        {
            get { return browser.HtmlSource; }
            set { browser.HtmlSource = value; }
        }

        public Uri SourceUrl
        {
            get { return browser.SourceUrl; }
            set { browser.SourceUrl = value; }
        }
    }
}
